package admin.controllers;

import helpers.PaginatorHelper;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.AutoSite;

import data.AutoSiteData;

public class ListSiteServlet extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		
		AutoSiteData autoSiteData = new AutoSiteData();
		ArrayList<AutoSite> sites = autoSiteData.getAlls();
		
		//Get paginate
		String queryString = request.getQueryString();
		String requestURI = request.getRequestURI();
		PaginatorHelper paginator = new PaginatorHelper(queryString);
		paginator.setUrl(requestURI);
		
		request.setAttribute("sites", sites);
		try {
			request.getRequestDispatcher("/admin/pages/list_site.jsp").forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
